{% extends "../layout.html" %}

{% block content %}
<div class="dy-wrapper">
  <a href="/backend/product/create" class="btn btn-sky-blue  mb-3">添加</a>

  <div class="dy-search">
    <form class="row g-3" method="get" action="/backend/product/list">
      <div class="col-3 mb-3">
        <div class="row ">
          <label for="name" class="col-sm-3 col-form-label">名称</label>
          <div class="col-sm-9">
            <input type="text" class="form-control" id="name" name="name" />
          </div>
        </div>
      </div>
      <div class="col-3 mb-3">
        <div class="row">
          <label for="cid" class="col-sm-4 col-form-label">分类</label>
          <div class="col-sm-8">
            <select class="form-select" id="cid" name="cid">
              <option value="0">请选择</option>
              {% for item in taxons %}
              <option value="{{ item.id }}">{{ item.name }}</option>
              {% endfor %}
            </select>
          </div>
        </div>
      </div>
      <div class="col-3 mb-3">
        <button type="submit" class="btn btn-sky-blue  mb-3">搜索</button>
      </div>
    </form>
  </div>


  <table class="table table-bordered table-hover">
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">名称</th>
          <th scope="col">分类</th>
          <th scope="col">图片</th>
          <th scope="col" width="100">是否在售</th>
          <th scope="col" width="100">价格</th>
          <th scope="col" width="100">销量</th>
          <th scope="col" width="100">点击</th>
          <th scope="col" width="120">创建日期</th>
          <th scope="col" width="120">更新时间</th>
          <th scope="col" width="150">操作</th>
        </tr>
      </thead>
      <tbody>
        {% for data in list %}
        <tr>
          <th scope="row">{{ data.id }}</th>
          <td>{{ data.name }}</td>
          <td>{{ data.taxon_name }}</td>
          <td>
            {% if !data.image.is_empty() %}
            <img src="{{ data.image }}" height="30" />
            {% endif %}
          </td>
          <td>
            {% if data.is_sale == 1 %}
            是
            {% else %}
            否
            {% endif %}
          </td>
          <td>{{ data.price }}</td>
          <td>{{ data.sales }}</td>
          <td>{{ data.hits }}</td>
          <td>{{ data.created_at.format("%Y-%m-%d") }}</td>
          <td>{{ data.updated_at.format("%Y-%m-%d") }}</td>
          <td>
            <a href="/backend/product/edit/{{ data.id }}" class="btn btn-success btn-sm">编辑</a>
            <a href="javascript:void(0)" data-url="/backend/product/delete/{{ data.id }}" class="btn btn-danger btn-sm deleteResource">删除</a>
          </td>
        </tr>
        {% endfor %}
      </tbody>
  </table>

  <nav aria-label="Page navigation example">
      <ul class="pagination justify-content-end">
        {{ paginate|safe  }}
      </ul>
  </nav>
</div>
{% endblock %}